package view.components;

import java.util.ArrayList;
import java.awt.Dimension;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JEditorPane;

/**
 * Creates the history window that displays the previous commands the user has
 * entered.
 * 
 * @author Yin, Alex
 * 
 */
@SuppressWarnings("serial")
public class SLogoHistoryCommands extends JEditorPane {
    private List<String> myHistoryCommands;

    public SLogoHistoryCommands() {
        myHistoryCommands = new ArrayList<String>();

        setOpaque(true);
        setEditable(false);
        setPreferredSize(new Dimension(200, 200));
        this.setVisible(true);

        this.setBorder(BorderFactory.createRaisedBevelBorder());

        this.setPreferredSize(new Dimension(200, 250));
        this.setOpaque(true);

    }

    /**
     * shows previous valid commands entered
     * 
     * @param input
     *            string to be displayed
     */
    public void showString(String input) {
        if (input != null) {
            myHistoryCommands.add(input);
            String output = listToString(myHistoryCommands);
            setText(output);
        }
    }

    /**
     * converts list of strings into a formatted string to be displayed
     * 
     * @param list
     *            list of previous commands
     * @return formatted string of commands
     */
    private String listToString(List<String> list) {
        String output = "";
        for (String str : list) {
            output += str + "\n";
        }
        return output;
    }

    /**
     * 
     * @return list of previous commands
     */
    public List<String> getHistory() {
        return myHistoryCommands;
    }

}
